Open
Conversation
This factory will look at the file's extension and determine which class implementation to use.
The purpose of these classes is to allow for custom callback's which can be called before or after a record is created. This allows for a developer to perform data massaging or error reporting as an example.
- Using Newspack Listing Type pseudo enum class. - Using Newspack Listing Import mode. - Using Newspack Listing Type mapper. - Fleshing out the import process for posts. - Fleshing out the import process for images.
…ontains instead of ends_with
The brackets are part of the custom templating syntax. This also addresses an oversight whereby the featured image template is not used because it comes after the return of the finished custom template.
Member
|
@eddiesshop – what's the status here? Is this still awaiting review, or maybe should be reverted to draft or closed? |
Author
|
Hey @adekbadek, while I do use this to import listings from time to time, it probably needs to be reworked a bit. There are some places where it would make more sense to use filters (for callbacks) instead of how it's currently set up. There's also a bit of complexity which could be simplified. Ultimately though, I would ask @dkoo to see if he thinks this is even still necessary? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
All Submissions:
Changes proposed in this Pull Request:
Closes # .
How to test the changes in this Pull Request:
Other information:
We’ve used it for the Rafu. I think Zak perhaps may have used the importer as well.
The command structure is like this:
wp newspack-listings import /var/www/html/rafu-listings-cleaned.csv --mode=dry-run --pre-create-callback=/var/www/html/pre-create-callback-rafu.php,\\Rafu\\Rafu_Pre_Create_Callback. I think it could be improved if we change it to rely on apply_filters instead of using the PreCreateAbstractClass.These templates are supposed to be a “standard” listings template, much like how we have post blocks on the site. It’s supposed to make it a simpler experience/matter to import listings. It’s a decision I made to try to steer the listings development in a direction where it can be standardized in the future.
The code also allows for the use of a custom template if none of the “standard” ones are to be used
I like using the php function strtr (explanation here). It allows you to have placeholders in a string, which you can then replace with whatever you’d like. Sort of like sprintf except, you can name the string placeholder so that it’s easier to read and figure out what is expected to replace the placeholder.
So in the case of event-dates, the function would look like this:
strtr( $event_date_template, [ '{start_date}' => '2022-09-27' ] )The above would generate a string like this:
<!-- wp:newspack-listings/event-dates {"startDate":"2022-09-27"} /-->